let axios = require('axios');
let FormData = require('form-data');
let data = new FormData();

export function requestGetToken(e) {
  let info=JSON.stringify({
    'username':e[0],
    'password':e[1]
  })
  let  config = {
    method: 'post',
    url: 'http://47.102.99.215:9090/peach/authentication/form?username='+e[0]+'&password='+e[1],
    headers: {
      'Content-Type': 'application/json'
    },
    data:info
  };
  return axios(config)
}
export function requestRegister(e) {
  let info=JSON.stringify({
    'username':e[0],
    'password':e[1]
  })
  let config2 = {
    method: 'post',
    url: 'http://47.102.99.215:9090/peach/user/register',
    headers: {
      'Content-Type': 'application/json'
    },
    data : info
  }
  return axios(config2)
}

export function requestUserInfo(e) {
  let authorization = 'Bearer ' + e
  let config4 = {
    method: 'get',
    url: 'http://47.102.99.215:9090/peach/user/getUser',
    headers: {
      'Authorization': authorization
    }
  }
  return axios(config4)
}
export function requestAllInfo(e) {
  let authorization = 'Bearer ' + e
  let config4 = {
    method: 'get',
    url: 'http://47.102.99.215:9090/peach/attendance/getAllAttendance',
    headers: {
      'Authorization': authorization
    }
  }
  return axios(config4)
}
export function requestMorInfo(e) {
  let [token,day] = e
  let authorization = 'Bearer ' + token
  console.log(token,day)
  let config6 = {
    method: 'get',
    url: 'http://47.102.99.215:9090/peach/attendance/getAttendanceByTime?beginTimeS='+day+' 00:00:00'+'&endTimeS='+day+' 11:59:59',
    headers: {
      'Authorization': authorization
    }
  }
  return axios(config6)
}
export function requestAftInfo(e) {
  let [token,day] = e
  let authorization = 'Bearer ' + token
  console.log(token,day)
  let config6 = {
    method: 'get',
    url: 'http://47.102.99.215:9090/peach/attendance/getAttendanceByTime?beginTimeS='+day+' 12:00:00'+'&endTimeS='+day+' 23:59:59',
    headers: {
      'Authorization': authorization
    }
  }
  return axios(config6)
}
export function requestGetLocation(e){
  let lat=e.startLatitude
  let lon = e.startLongitude
  let config5 = {
    method: 'get',
    url: 'https://restapi.amap.com/v3/geocode/regeo?output=JSON&location='+lat+','+lon+'&key=a36523c376589d080f345338c9eb03c0',
    headers: {

    }

  }
  return axios(config5)
}
export function requestUpload(e){
  let data = new FormData();
  data.append('file',e[1]);
  let authorization = 'Bearer ' + e[0]
  let config9 = {
    method: 'post',
    url: 'http://47.102.99.215:9090/peach/user/uploadPortrait',
    headers: {
      'Authorization': authorization
    },
    data : data
  }
  return axios(config9)
}

  export function requestChange(e){
    let data = JSON.stringify({
      [e[2]]: e[1]
    });
    console.log(data)
    let authorization = 'Bearer ' + e[0]
    let config10 = {
      method: 'post',
      url: 'http://47.102.99.215:9090/peach/user/perfectInformation',
      headers: {
        'Authorization': authorization,
        'Content-Type': 'application/json'
      },
      data : data
    }
    return axios(config10)
  }
